package com.everflourish.yeah100.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.everflourish.yeah100.R;
import com.everflourish.yeah100.entity.marking.ObjectAnswer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 作者：Created by liqisi on 2016/10/21.
 * 时间：2016/10/21
 */
public class ObjectAnswerAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;
    private List<ObjectAnswer> mList;
    private ArrayList<Map<String, Object>> mStaList;

    public ObjectAnswerAdapter(Context mContext, List<ObjectAnswer> mList, ArrayList<Map<String, Object>> mStaList) {
        this.mInflater = LayoutInflater.from(mContext);
        this.mContext = mContext;
        this.mList = mList;
        this.mStaList = mStaList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ObjectAnswer objectAnswer = mList.get(position);
        HolderView holderView = null;
        if (convertView == null) {
            holderView = new HolderView();
            convertView = mInflater.inflate(R.layout.item_object_answer,
                    parent, false);
            holderView.objectNo = (TextView) convertView
                    .findViewById(R.id.e_topic_no);
            holderView.objectAnswer = (TextView) convertView
                    .findViewById(R.id.e_object_answer);
            holderView.objectAnswerItem = (LinearLayout) convertView.findViewById(R.id.e_object_answer_ll);
            convertView.setTag(holderView);
        } else {
            holderView = (HolderView) convertView.getTag();
        }
        String answer = objectAnswer.getAnswer();
        int serialNumber = objectAnswer.getSerialNumber();
        holderView.objectNo.setText(serialNumber + "");
        if (TextUtils.isEmpty(answer)) {// 答案为空
            holderView.objectAnswerItem.setBackgroundColor(mContext.getResources()
                    .getColor(R.color.e_standard_item_null));
        } else {
            if ((position + 1) % 2 == 0) {
                holderView.objectAnswerItem.setBackgroundColor(mContext
                        .getResources()
                        .getColor(R.color.e_standard_item_double));
            } else {
                holderView.objectAnswerItem.setBackgroundColor(mContext
                        .getResources()
                        .getColor(R.color.e_standard_iten_single));
            }
        }
        holderView.objectAnswer.setText(answer);
        return convertView;
    }

    class HolderView {
        public LinearLayout objectAnswerItem = null;
        public TextView objectNo = null;
        public TextView objectAnswer = null;
    }
}
